<template>
  <div class="stationTransaction">
    <basic-container>
      <avue-crud
        ref="crud"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="getList"
        @on-load="getList">
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
        </template>
        <template slot-scope="scope" slot="lineCodeSearch">
          <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" clearable filterable>
            <el-option
              v-for="(item,index) in lineCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="stationCodeSearch">
          <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" clearable @change="changeStation" filterable>
            <el-option
              v-for="(item,index) in stationCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot="menuRight">
          <el-button class="filter-item" type="primary" size="mini" @click="exportExcel()" v-if="false">导出</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <!-- <el-button type="text" size="small" hidden="hidden" v-if="scope.row.stationFile != '[]'" plain @click.stop="download(scope.row,1)">车站附件下载</el-button>
          <el-button type="text" size="small" hidden="hidden" v-if="scope.row.lineFile != '[]'" plain @click.stop="download(scope.row,2)">线网附件下载</el-button> -->
          <el-button type="text" size="small"  plain @click.stop="previewEditor(scope.row,3)">预览</el-button>
        </template>
      </avue-crud>
    </basic-container>
    <editorOrAdd ref="editorOrAdd"></editorOrAdd>
  </div>
</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {mapGetters} from 'vuex';
  import editorOrAdd from './KZDLCK/editorOrAdd.vue';
  import { handleDown } from '@/util/util';
  import {handleDownloadZip} from '@/util/util.js';
  import {
    getLineAllAsyn,
    getStationByCode,
    getSwPmTvmCodeList,
    setSearchFiledsEmpty,getLineCodes
  } from "../../../../api/subwayRat/commonCheck";
  import {exportDataToExcel} from "../../../../api/subwayRat/exportSelf";
  import transitUtil from "../../../../api/subwayRat/transitUtil";
  import {xw_other_tableOption,delete_xw_SwStApplyNetworkCheckPassengerAffairs,
    get_xw_SwStApplyNetworkCheckPassengerAffairs, getSysUserToLine, submit_xw_SwStApplyNetworkCheckPassengerAffairs,} from "../../../../api/stationTiecketManager/shuJuXieChaGuanLi/SQXWXCCKSW/otherYunYing";
  export default {
    components: {editorOrAdd},
    name: 'stationTransaction',
    data() {
      return {
        selectKeys:[], //存放对像
        selectKeyVals:[], //存放值
        userList : [],
        userCode : '',
        username : '',
        option: xw_other_tableOption,
        optionTwo: {},
        dialogOption: {},
        formData: {},
        listLoading: true,
        isReload: true,
        editorDialogVisible: false,
        searchForm:{
          lineCode:'',
          stationCode:'',
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条,
          isAsc: false// 是否倒序
        },
        list : [],
        listTwo : [],
        lineCodes:[],
        stationCodes:[],
        fileType : 0,
        showType : true
      }
    },
    computed: {
    },
    watch: {
    },
    mounted() {
      // getLineAllAsyn().then(res=>{ //获取线路
      //   this.lineCodes=res.data;
      // });
      getLineCodes().then(res=>{ //获取线路
          this.lineCodes=res;
      });
    },
    created() {
    },
    methods: {
      setSearchFiledsEmpty,
      add(){
        this.$refs.editorOrAdd.show(null,2);
      },
      uploadBefore(res, done, loading,column) {
          if("stationFile" == column.prop){
            this.fileType = 1;
          }else{
            this.fileType = 2;
          }
          done()
      },
      deleteSwStApplyNetworkCheckPassengerAffairs() {
        if(this.selectKeys.length<=0){
          this.$message.warning("请选择一条数据操作！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
          if(this.selectKeys[i].applyStatus==1){
            this.$message.warning("请选择未提交数据操作！");
            return;
          }
        }

        delete_xw_SwStApplyNetworkCheckPassengerAffairs({ids:this.selectKeyVals.join(',')}).then((res)=>{
          if(res.data.code==0){
            this.$message.success("操作成功！");
            this.getList();
          }else{
            this.$message.error("操作失败！");
          }
        });
      },
      // download(row,type){
      //     if(1==type){
      //       handleDown(row.stationFile,"zdkj")
      //     }else{
      //       handleDown(row.lineFile,"zdkj")
      //     }
      // },
      download(row,type) {
        let pathList = [];
        if(1==type){
          debugger
          if (!this.validatenull(row.stationFile)) {
            pathList.push(row.stationFile);
          }
          if (pathList[0] == "[]") {
            this.$message.info("无附件");
            return;
          }
          handleDownloadZip(pathList, "车站附件.zip");
        }else{
          if (!this.validatenull(row.lineFile)) {
            pathList.push(row.lineFile);
          }
          if (pathList[0] == "[]") {
            this.$message.info("无附件");
            return;
          }
          handleDownloadZip(pathList, "线网附件.zip");
        }

      },
      async exportExcel(){ // 导出
        debugger
        let p={};
        Object.assign(p,this.searchForm);
        p.pageNo=1;
        p.pageSize=1000000000;
        if(this.selectKeys.length>0){
          let newData = JSON.parse(JSON.stringify(this.selectKeys));
          exportDataToExcel(newData,this.option.column,'车站提交事务协查申请审核');
        }else {
          let res=await get_xw_SwStApplyNetworkCheckPassengerAffairs(p);
          let data = res.data.data;
          exportDataToExcel(data,this.option.column,'车站提交事务协查申请审核');
        }
      },
      submit(){
        if(this.selectKeys.length<=0){
          this.$message.warning("请选择一条数据操作！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
          if(this.selectKeys[i].applyStatus==1){
            this.$message.warning("请选择未提交数据操作！");
            return;
          }
        }
        submit_xw_SwStApplyNetworkCheckPassengerAffairs({ids:this.selectKeyVals.join(',')}).then((res)=>{
            if(res.data.code==0){
              this.$message.success("操作成功！");
              this.getList();
            }else{
              this.$message.error("操作失败！");
            }
          });
          this.editorDialogVisible = false;
      },
      changeLine(row){
          this.userCode = row;
      },
      back(){
          this.editorDialogVisible = false;
      },
      async previewEditor(row,type){
        this.$refs.editorOrAdd.show(row,type);
      },
      getList() {
        this.listLoading = true;
        Object.assign(this.searchForm,this.page);
        this.searchForm.userCode = this.$store.getters.userInfo.userCode;
        get_xw_SwStApplyNetworkCheckPassengerAffairs(this.searchForm).then((response)=>{
          this.list = response.data.data
          this.listLoading = false
          this.page.total=response.data.total;
        });
      },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList()
        done()
      },
    changeLine(v){ //改变线路时
      getStationByCode({line_code:v}).then(res=>{
        this.stationCodes=res.data;
        this.searchForm.stationCode='';
      });
    },
    changeStation(v){

    },
      selectionChange(list){
        this.selectKeys=list;
        this.selectKeyVals=[];
        for(let i=0;i<list.length;i++){
          this.selectKeyVals.push(list[i].id);
        }
      }
    }
  }
</script>
<style lang="scss">
</style>
